load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "builtins",
    srcs = [
        "aggregate_builtins.go",
        "all_builtins.go",
        "builtins.go",
        "compression.go",
        "fingerprint_builtins.go",
        "fixed_oids.go",
        "generator_builtins.go",
        "generator_probe_ranges.go",
        "geo_builtins.go",
        "math_builtins.go",
        "notice.go",
        "overlaps_builtins.go",
        "parse_ident_builtin.go",
        "pg_builtins.go",
        "pgcrypto_builtins.go",
        "pgvector_builtins.go",
        "replication_builtins.go",
        "show_create_all_schemas_builtin.go",
        "show_create_all_tables_builtin.go",
        "show_create_all_types_builtin.go",
        "trigram_builtins.go",
        "tsearch_builtins.go",
        "window_builtins.go",
        "window_frame_builtins.go",
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/build",
        "//pkg/clusterversion",
        "//pkg/config/zonepb",
        "//pkg/geo",
        "//pkg/geo/geogfn",
        "//pkg/geo/geoindex",
        "//pkg/geo/geomfn",
        "//pkg/geo/geopb",
        "//pkg/geo/geoprojbase",
        "//pkg/geo/geos",
        "//pkg/geo/geotransform",
        "//pkg/geo/twkb",
        "//pkg/jobs/jobspb",
        "//pkg/keys",
        "//pkg/kv",
        "//pkg/kv/kvclient",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver/kvserverbase",
        "//pkg/repstream/streampb",
        "//pkg/roachpb",
        "//pkg/security/password",
        "//pkg/security/username",
        "//pkg/server/telemetry",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/sql/appstatspb",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/catalogkeys",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/randgen/randgencfg",
        "//pkg/sql/colexecerror",
        "//pkg/sql/lex",
        "//pkg/sql/lexbase",
        "//pkg/sql/memsize",
        "//pkg/sql/oidext",
        "//pkg/sql/opt/workloadindexrec",
        "//pkg/sql/parser",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/pgwire/pgnotice",
        "//pkg/sql/privilege",
        "//pkg/sql/protoreflect",
        "//pkg/sql/rowenc",
        "//pkg/sql/rowenc/keyside",
        "//pkg/sql/rowenc/valueside",
        "//pkg/sql/sem/asof",
        "//pkg/sql/sem/builtins/builtinconstants",
        "//pkg/sql/sem/builtins/builtinsregistry",
        "//pkg/sql/sem/builtins/pgcrypto",
        "//pkg/sql/sem/builtins/pgformat",
        "//pkg/sql/sem/cast",
        "//pkg/sql/sem/catconstants",
        "//pkg/sql/sem/catid",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sem/volatility",
        "//pkg/sql/sessiondata",
        "//pkg/sql/sessiondatapb",
        "//pkg/sql/sqlerrors",
        "//pkg/sql/sqlliveness",
        "//pkg/sql/sqlstats/persistedsqlstats/sqlstatsutil",
        "//pkg/sql/sqltelemetry",
        "//pkg/sql/storageparam",
        "//pkg/sql/storageparam/indexstorageparam",
        "//pkg/sql/syntheticprivilege",
        "//pkg/sql/types",
        "//pkg/storage",
        "//pkg/storage/enginepb",
        "//pkg/util",
        "//pkg/util/arith",
        "//pkg/util/bitarray",
        "//pkg/util/duration",
        "//pkg/util/encoding",
        "//pkg/util/envutil",
        "//pkg/util/errorutil/unimplemented",
        "//pkg/util/fuzzystrmatch",
        "//pkg/util/hlc",
        "//pkg/util/humanizeutil",
        "//pkg/util/intsets",
        "//pkg/util/ipaddr",
        "//pkg/util/json",
        "//pkg/util/log",
        "//pkg/util/mon",
        "//pkg/util/pretty",
        "//pkg/util/protoutil",
        "//pkg/util/randident",
        "//pkg/util/randident/randidentcfg",
        "//pkg/util/randutil",
        "//pkg/util/rangedesc",
        "//pkg/util/ring",
        "//pkg/util/syncutil",
        "//pkg/util/timeofday",
        "//pkg/util/timetz",
        "//pkg/util/timeutil",
        "//pkg/util/timeutil/pgdate",
        "//pkg/util/tochar",
        "//pkg/util/tracing",
        "//pkg/util/tracing/tracingpb",
        "//pkg/util/trigram",
        "//pkg/util/tsearch",
        "//pkg/util/ulid",
        "//pkg/util/unaccent",
        "//pkg/util/uuid",
        "//pkg/util/vector",
        "@com_github_cockroachdb_apd_v3//:apd",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_golang_geo//s1",
        "@com_github_golang_snappy//:snappy",
        "@com_github_klauspost_compress//gzip",
        "@com_github_klauspost_compress//zstd",
        "@com_github_knz_strtime//:strtime",
        "@com_github_lib_pq//oid",
        "@com_github_pierrec_lz4_v4//:lz4",
        "@com_github_twpayne_go_geom//:go-geom",
        "@com_github_twpayne_go_geom//encoding/ewkb",
        "@org_golang_x_crypto//bcrypt",
        "@org_golang_x_text//cases",
        "@org_golang_x_text//language",
    ],
)

go_test(
    name = "builtins_test",
    size = "medium",
    srcs = [
        "aggregate_builtins_test.go",
        "all_builtins_test.go",
        "builtins_test.go",
        "cast_test.go",
        "datums_to_bytes_builtin_test.go",
        "fingerprint_builtin_test.go",
        "generator_builtins_test.go",
        "geo_builtins_test.go",
        "help_test.go",
        "helpers_test.go",
        "main_test.go",
        "math_builtins_test.go",
        "parse_ident_builtin_test.go",
        "show_create_all_tables_builtin_test.go",
        "window_frame_builtins_test.go",
    ],
    data = glob(["testdata/**"]),
    embed = [":builtins"],
    exec_properties = select({
        "//build/toolchains:is_heavy": {"test.Pool": "large"},
        "//conditions:default": {"test.Pool": "default"},
    }),
    deps = [
        "//pkg/base",
        "//pkg/kv",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver",
        "//pkg/roachpb",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/server",
        "//pkg/settings/cluster",
        "//pkg/sql/catalog/desctestutils",
        "//pkg/sql/parser",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/randgen",
        "//pkg/sql/sem/builtins/builtinconstants",
        "//pkg/sql/sem/builtins/builtinsregistry",
        "//pkg/sql/sem/cast",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sem/tree/treewindow",
        "//pkg/sql/sem/volatility",
        "//pkg/sql/types",
        "//pkg/storage",
        "//pkg/storage/enginepb",
        "//pkg/testutils",
        "//pkg/testutils/datapathutils",
        "//pkg/testutils/fingerprintutils",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/skip",
        "//pkg/testutils/sqlutils",
        "//pkg/testutils/storageutils",
        "//pkg/testutils/testcluster",
        "//pkg/util",
        "//pkg/util/duration",
        "//pkg/util/hlc",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/mon",
        "//pkg/util/randutil",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "@com_github_lib_pq//:pq",
        "@com_github_lib_pq//oid",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
    ],
)

disallowed_imports_test(
    src = "builtins",
    disallowed_list = [
        "//pkg/sql/catalog/descs",
        "//pkg/sql/catalog/tabledesc",
        "//pkg/sql/catalog/schemadesc",
        "//pkg/sql/catalog/dbdesc",
        "//pkg/sql/catalog/typedesc",
    ],
)
